package com.xf.toy.dao.page;

import java.util.List;

public class Pagination {
	private Integer pageSize = 10; // 每页显示记录数
	private Integer currentPage = 1; // 当前页码
	private Integer maxPage = Integer.MAX_VALUE; // 最大页数
	private Integer start = 0;
	private Integer totalcount=0;

	

	public Integer getTotalcount() {
		return totalcount;
	}

	public void setTotalcount(Integer totalcount) {
		this.totalcount = totalcount;
	}

	public Integer getStart() {
		if (start == 0)
			return (currentPage - 1) * pageSize;
		else
			return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	// 获取offset
	public Integer getOffset() {
		return (currentPage - 1) * pageSize;
	}

	// 获取limit
	public Integer getLimit() {
		return getPageSize();
	}

	public Integer getMaxPage(Integer total) {
		if (total % pageSize == 0) {
			return total / pageSize;
		} else {
			return total / pageSize + 1;
		}
	}

	
	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		if(currentPage==null){
			currentPage=null;
			return;}
		if (currentPage < 1)
			currentPage = 1;
		if (currentPage > maxPage)
			currentPage = maxPage;
		this.currentPage = currentPage;
	}

	public Integer getMaxPage() {
		return maxPage;
	}

	public void setMaxPage(Integer maxPage) {
		this.maxPage = maxPage;
	}

}
